Moze nie jest to najodpowiedniejsza grupa na tego posta, ale mysle
ze ktos, kto zajmowal spoofingiem bedzie mi w stanie odpowiedziec
na to pytanie:
Chodzi mi o liczenie checksum w naglowku tcp, aby to zrobic nalezy
oprocz samego naglowka otraz tresci pakietu dodac prefiks w postaci
"naglowka" zawierajacego adres nadawcy, odbiorcy, protokol, oraz dlugosc
dopiero sumowac. Moje pytanie dotyczy wlasnie tajemniczego protokolu
i jeszcze bardziej tajemniczej jego dlugosci, co tam wstawic?
dziekuje z gory
DM
Suma kontrolna naglowka TCP...
AFAIK do niej sie nie wlicza naglowka IP (ma on wlasna sume kontrolna)
A ten twoj "prefix"... czy to nie jest przypadkiem naglowek IP?
Ten "tajemniczy protokol" to IPv4 lub IPv6...
"Jego dlugosc" to chyba dlugosc adresu, tak? (dla IPv4 - 4 bajty)
A moze dlugosc naglowka IP? (20 bajtow)
Lub TCP - 32 bajty?
Napisz cos wiecej..
BTW: czy system przypadkiem sumy kontrolnej sam nie liczy?
Nie zrozumialem Cie zbyt dobrze...
Suma kontrolna naglowka TCP...
AFAIK do niej sie nie wlicza naglowka IP (ma on wlasna sume kontrolna)
A ten twoj "prefix"... czy to nie jest przypadkiem naglowek IP?
Ten "tajemniczy protokol" to IPv4 lub IPv6...
"Jego dlugosc" to chyba dlugosc adresu, tak? (dla IPv4 - 4 bajty)
A moze dlugosc naglowka IP? (20 bajtow)
Lub TCP - 32 bajty?
Napisz cos wiecej..
Zacytuje RFC794
Checksum: 16 bits
The checksum field is the 16 bit one's complement of the one's
complement sum of all 16 bit words in the header and text. If a
segment contains an odd number of header and text octets to be
checksummed, the last octet is padded on the right with zeros to
form a 16 bit word for checksum purposes. The pad is not
transmitted as part of the segment. While computing the checksum,
the checksum field itself is replaced with zeros.
The checksum also covers a 96 bit pseudo header conceptually
prefixed to the TCP header. This pseudo header contains the Source
Address, the Destination Address, the Protocol, and TCP length.
This gives the TCP protection against misrouted segments. This
information is carried in the Internet Protocol and is transferred
across the TCP/Network interface in the arguments or results of
calls by the TCP on the IP.
+--------+--------+--------+--------+
| Source Address |
+--------+--------+--------+--------+
| Destination Address |
+--------+--------+--------+--------+
| zero | PTCL | TCP Length |
+--------+--------+--------+--------+
tego pola w pliku naglowkowym
BTW: czy system przypadkiem sumy kontrolnej sam nie liczy?
liczy ale ja akurat bawie sie berkeley packet filter a on egzystuje na
poziomie protokolu ethernet
dzieki za zainteresowanie
DM
+--------+--------+--------+--------+
| Source Address |
+--------+--------+--------+--------+
| Destination Address |
+--------+--------+--------+--------+
| zero | PTCL | TCP Length |
+--------+--------+--------+--------+
typedef u_long tcp_seq;
// Dla przypomnienia :)
struct tcphdr {
u_short th_sport; /* source port */
u_short th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
#if __BYTE_ORDER == __LITTLE_ENDIAN
u_char th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
u_char th_off:4, /* data offset */
th_x2:4; /* (unused) */
#endif
u_char th_flags;
#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20
u_short th_win; /* window */
u_short th_sum; /* checksum */
u_short th_urp; /* urgent pointer */
ipheader-version=4;
ipheader-ihl=sizeof(struct iphdr)/4;
ipheader-tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr));
ipheader-id=htons(ld-sequence_number);
ipheader-ttl = ld-ttl;
ipheader-protocol = ld-ip_protocol;
ipheader-saddr=sin.sin_addr.s_addr;
ipheader-daddr=sin.sin_addr.s_addr;
tcpheader-th_sport = sin.sin_port;
tcpheader-th_dport = sin.sin_port;
tcpheader-th_seq = htonl(ld-sequence_number);
tcpheader-th_flags = ld-tcp_flags;
tcpheader-th_off = sizeof(struct tcphdr)/4;
tcpheader-th_win = htons(ld-window_size);
bzero(&pseudoheader,12+sizeof(struct tcphdr));
pseudoheader.saddr.s_addr=sin.sin_addr.s_addr;
pseudoheader.daddr.s_addr=sin.sin_addr.s_addr;
pseudoheader.protocol = ld-ip_protocol;
To jest chyba ten TCP length
pseudoheader.length = htons(sizeof(struct tcphdr));
bcopy((char *) tcpheader,(char *)
&pseudoheader.tcpheader,sizeof(struct tcphdr));
tcpheader-th_sum = checksum((u_short *)
&pseudoheader,12+sizeof(struct tcphdr));
A co do liczenia tej sumy kontrolnej...
u_short checksum(u_short * data,u_short length)
{
register long value;
u_short i;
for(i = 0; i< (length | 1); i++)
value += data[i];
if((length & 1)==1)
value += (data[i] << 8);
value = (value & 0xFFFF) + (value | 16);
return(~value);
PS. Nie wiem czy to Ci w czyms pomoze...
Hmm? Mozna wiedziec co Ty chcesz zrobic?
Pozdrawiam,
DM